package com.lancoo.znbkxx.teacher.aibkTestCoach.aibkPublicActivity

import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ErrorRecovery
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.base.BaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.base.BaseRecyclerViewHolder
import kotlinx.android.synthetic.main.adapter_item_error_recovery.view.*

/**
 * auther: 王国龙
 * Date：
 * describe:
 */
class AibkAdapterErrorRecovery(
         val context: Context,
         val errorRecovery: List<ErrorRecovery>
) : BaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup, position: Int): View {
        return LayoutInflater.from(context)
                .inflate(R.layout.adapter_item_error_recovery, parent, false)
    }

    override fun onBindViewHolder(holder: BaseRecyclerViewHolder, position: Int) {
        holder.convertView.TvRecovery.text = errorRecovery[position].Error
        holder.convertView.CheckBoxErrorRecovery.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                holder.convertView.CheckBoxErrorRecovery.isChecked = true
                errorRecovery[position].Priority = 1
            } else {
                holder.convertView.CheckBoxErrorRecovery.isChecked = false
                errorRecovery[position].Priority = 0
            }
        }
    }

    override fun getItemCount(): Int {
        return errorRecovery.size
    }

}